package ontocompo.fractalcomponentmanager.lib;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;

import ontocompo.fractalcomponentmanager.api.UIElementItf;
import ontocompo.fractalcomponentmanager.enums.Role;

import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.BindingController;
import org.objectweb.fractal.api.control.NameController;

public class CompoApplication {
	private ArrayList<WebApplication> baseWebApp;
	private String elementToKeepId;
	
	private HashMap<String, String> generatedClass;
	private HashMap<String, String> components;
	private HashMap<String, String> bindings;
	
	private String appName;
	
	public CompoApplication() {
		this.baseWebApp = new ArrayList<WebApplication>();
		this.elementToKeepId = null;
		this.generatedClass = new HashMap<String, String>();
		this.components = new HashMap<String, String>();
		this.bindings = new HashMap<String, String>();
	}
	
	public void setAppName(String appName) {
		this.appName = appName;
	}
	
	public void addToBaseWebApp(WebApplication wa) {
		if(! this.baseWebApp.contains(wa)) {
			this.baseWebApp.add(wa);
		}
	}
	
	public void performSubstitution(String elementId) {
		this.elementToKeepId = elementId;
		performSuccessiveSubstitutions();
	}
	
	public void performSuccessiveSubstitutions() {
		HashMap<String, Component> selectedElements = new HashMap<String, Component>();
		
		for(WebApplication wa : this.baseWebApp) {
			selectedElements.putAll(wa.getSelectedElementsForSubstitutions());
		}
		
		selectedElements.remove(this.elementToKeepId);
		
		for(String elemId : selectedElements.keySet()) {
			substitute(this.elementToKeepId, elemId);
		}
		
		for(WebApplication wa : this.baseWebApp) {
			wa.reinitElementsForSubstitutions();
		}
	}
	
	public void substitute(String elemToKeep, String elemToSubstitute) {
		Role roleElemToKeep = null;
		Component componentElemToKeep = null;
		
		Role roleElemToSubstitute = null;
		Component componentElemToSubstitute = null;
		
		for(WebApplication wa : this.baseWebApp) {
			if(wa.containsElement(elemToKeep)) {
				roleElemToKeep = wa.getRoleOf(elemToKeep);
				componentElemToKeep = wa.getElementComponent(elemToKeep);
			}
			if(wa.containsElement(elemToSubstitute)) {
				roleElemToSubstitute = wa.getRoleOf(elemToSubstitute);
				componentElemToSubstitute = wa.getElementComponent(elemToSubstitute);
				wa.removeSelectedElement(elemToSubstitute);
			}
			if(roleElemToKeep != null && roleElemToSubstitute != null) {
				break;
			}
		}
		
		switch(roleElemToKeep) {
			case TRIGGER:
				switch(roleElemToSubstitute) {
					case TRIGGER: 
						this.trigger_trigger_substitution(elemToKeep, elemToSubstitute, componentElemToKeep, componentElemToSubstitute);
						break;
					case INPUT: break;
					case OUTPUT: break;
				}
				break;
			case INPUT:
				switch(roleElemToSubstitute) {
					case TRIGGER: break;
					case INPUT: 
						this.input_input_substitution(elemToKeep, elemToSubstitute, componentElemToKeep, componentElemToSubstitute);
						break;
					case OUTPUT:
						this.input_output_substitution(elemToKeep, elemToSubstitute, componentElemToKeep, componentElemToSubstitute);
						break;
				}
				break;
			case OUTPUT:
				switch(roleElemToSubstitute) {
					case TRIGGER: break;
					case INPUT:
						this.output_input_substitution(elemToKeep, elemToSubstitute, componentElemToKeep, componentElemToSubstitute);
						break;
					case OUTPUT:
						this.output_output_substitution(elemToKeep, elemToSubstitute, componentElemToKeep, componentElemToSubstitute);
						break;
				}
				break;
		}
		
	}
	
	public void trigger_trigger_substitution(String elemToKeep, String elemToSubstitute, Component componentElemToKeep, Component componentElemToSubstitute) {

		try {
			String adapterClassName = "Adapter" + Class.forName(elemToKeep).getSimpleName() + Class.forName(elemToSubstitute).getSimpleName();
			
			String providedInterfaces = "";
			String implementInterfaces = "ontocompo.api.IntrospectionItf";
			String requiredInterfaces = "";
			
			String methodsToImplement = "";
			
			NameController nameitf = (NameController)componentElemToKeep.getFcInterface("name-controller");
			String keepComponentName = nameitf.getFcName();
			
			BindingController bindingitf = (BindingController)componentElemToKeep.getFcInterface("binding-controller");
			String[] interfaces = bindingitf.listFc();
			
			for(String i: interfaces) {
				Interface keepInterface = (Interface) componentElemToKeep.getFcInterface(i);
				String interfaceNameKeep = (keepInterface.getFcItfType().toString().split("/"))[0];
				String interfaceuriKeep = (keepInterface.getFcItfType().toString().split("/"))[1];
				
				
				if(ontocompo.control.api.ControllerItf.class.getName().equals(interfaceuriKeep)) {
					requiredInterfaces += "\t@Requires(name = \"" + interfaceNameKeep + "\")" + "\n";
					requiredInterfaces += "\tprivate " + interfaceuriKeep + " " + interfaceNameKeep + ";" + "\n\n";
					
					Object o = bindingitf.lookupFc(i);
					Interface itfserver = (Interface) o;
					String interfaceName = (itfserver.getFcItfType().toString().split("/"))[0];
					String interfaceuri = (itfserver.getFcItfType().toString().split("/"))[1];
					Component controllerComponent = itfserver.getFcItfOwner();
					
					NameController controllerNameitf = (NameController)controllerComponent.getFcInterface("name-controller");
					String controllerComponentName = controllerNameitf.getFcName();
					
					this.bindings.put(adapterClassName + "Component." + interfaceNameKeep, controllerComponentName + "." + interfaceName);
					
					providedInterfaces += ", @Interface(name = \"" + interfaceName + "\", signature = " + interfaceuri + ".class)";
					
					this.bindings.put(keepComponentName + "." + interfaceNameKeep, adapterClassName + "Component." + interfaceName);
					
					implementInterfaces += ", " + interfaceuri;
					
					try {
						for(Method m : Class.forName(interfaceuri).getMethods()) {
							if(m.getName() != "getUid" && m.getName() != "setFractalComponent" && m.getName() != "getFractalComponent") {
								methodsToImplement += "\t@Override" + "\n";
								String parameters = "";
								Type[] parameterTypes = m.getGenericParameterTypes();
								if(parameterTypes.length > 0) {
									ArrayList<String> parametersArray = new ArrayList<String>();
									for(int j = 0; j < parameterTypes.length ; j++) {
										parametersArray.add(parameterTypes[j].toString() + " param" + j);
									}
									parameters = Resources.join(parametersArray, ",");
								}
								methodsToImplement += "\tpublic " + m.getGenericReturnType().toString() + " " + m.getName() + "(" + parameters + ") {" + "\n";
								methodsToImplement += "\t\t// TODO Auto-generated method stub" + "\n";
								methodsToImplement += "\t}" + "\n";
							}
						}
					} catch (SecurityException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (ClassNotFoundException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
			
			bindingitf = (BindingController)componentElemToSubstitute.getFcInterface("binding-controller");
			interfaces = bindingitf.listFc();
			
			for(String i: interfaces) {
				Interface substituteInterface = (Interface) componentElemToSubstitute.getFcInterface(i);
				String interfaceNameSubstitute = (substituteInterface.getFcItfType().toString().split("/"))[0];
				String interfaceuriSubstitute = (substituteInterface.getFcItfType().toString().split("/"))[1];
				
				
				if(ontocompo.control.api.ControllerItf.class.getName().equals(interfaceuriSubstitute)) {
					requiredInterfaces += "\t@Requires(name = \"" + interfaceNameSubstitute + "\")" + "\n";
					requiredInterfaces += "\tprivate " + interfaceuriSubstitute + " " + interfaceNameSubstitute + ";" + "\n\n";
					
					Object o = bindingitf.lookupFc(i);
					Interface itfserver = (Interface) o;
					String interfaceName = (itfserver.getFcItfType().toString().split("/"))[0];
					Component controllerComponent = itfserver.getFcItfOwner();
					
					NameController controllerNameitf = (NameController)controllerComponent.getFcInterface("name-controller");
					String controllerComponentName = controllerNameitf.getFcName();
					
					this.bindings.put(adapterClassName + "Component." + interfaceNameSubstitute, controllerComponentName + "." + interfaceName);
				}
			}
			
			String generated = this.generateAdapter(adapterClassName, providedInterfaces, implementInterfaces, requiredInterfaces, methodsToImplement);
			
			this.generatedClass.put(adapterClassName, generated);
			
			this.components.put(adapterClassName + "Component", "ontowebapp." + adapterClassName);
			
		} catch (NoSuchInterfaceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void input_input_substitution(String elemToKeep, String elemToSubstitute, Component componentElemToKeep, Component componentElemToSubstitute) {
		try {
			String adapterClassName = "Adapter" + Class.forName(elemToKeep).getSimpleName() + Class.forName(elemToSubstitute).getSimpleName();
			
			String providedInterfaces = "";
			ArrayList<String> providedInterfacesNames = new ArrayList<String>();
			String implementInterfaces = "ontocompo.api.IntrospectionItf";
			String requiredInterfaces = "";
			
			String methodsToImplement = "";
			
			Component controllerKeepComponent = null;
			
			for(WebApplication wa : this.baseWebApp) {
				controllerKeepComponent = wa.findControllerLinkToElement(elemToKeep);
				if(controllerKeepComponent != null) {
					break;
				}
			}
			
			if(controllerKeepComponent != null) {
				BindingController controllerBindingitf = (BindingController)controllerKeepComponent.getFcInterface("binding-controller");
				
				NameController controllerNameitf = (NameController)controllerKeepComponent.getFcInterface("name-controller");
				String controllerComponentName = controllerNameitf.getFcName();
				
				Object[] interfacesObjects = controllerKeepComponent.getFcInterfaces();
				for(Object o : interfacesObjects) {
					Interface controllerInterface = (Interface) o;
					String controllerInterfaceName = (controllerInterface.getFcItfType().toString().split("/"))[0];
					String controllerInterfaceUri = (controllerInterface.getFcItfType().toString().split("/"))[1];
					String controllerInterfaceType = (controllerInterface.getFcItfType().toString().split("/"))[2];
					
					if(controllerInterfaceType.equals("client")) {
						
						
						Interface elemInterface = (Interface) controllerBindingitf.lookupFc(controllerInterfaceName);
						Component elemComponent = elemInterface.getFcItfOwner();
						
						ontocompo.api.IntrospectionItf elemIi = ontocompo.api.IntrospectionItf.class.cast(elemComponent.getFcInterface("ontocompoIntrospectionItf"));
						String elemUid = elemIi.getUid();
						
						if(elemUid.equals(elemToKeep)) {
							if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
								String[] controllerComponentNameArray = this.bindings.get(controllerComponentName + "." + controllerInterfaceName).split("\\.");
								controllerComponentName = controllerComponentNameArray[0];
								if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
									this.bindings.remove(controllerComponentName + "." + controllerInterfaceName);
								}
							}
							
							String elemInterfaceName = (elemInterface.getFcItfType().toString().split("/"))[0];
							String elemInterfaceUri = (elemInterface.getFcItfType().toString().split("/"))[1];
							
							NameController elemNameitf = (NameController)elemComponent.getFcInterface("name-controller");
							String elemComponentName = elemNameitf.getFcName();
							
							requiredInterfaces += "\t@Requires(name = \"" + controllerInterfaceName + "\")" + "\n";
							requiredInterfaces += "\tprivate " + controllerInterfaceUri + " " + controllerInterfaceName + ";" + "\n\n";
							
							this.bindings.put(adapterClassName + "Component." + controllerInterfaceName, elemComponentName + "." + elemInterfaceName);							
							this.bindings.put(controllerComponentName + "." + controllerInterfaceName, adapterClassName + "Component." + elemInterfaceName);
							if(! providedInterfacesNames.contains(elemInterfaceName)) {
								providedInterfaces += ", @Interface(name = \"" + elemInterfaceName + "\", signature = " + elemInterfaceUri + ".class)";
								implementInterfaces += ", " + elemInterfaceUri;
								providedInterfacesNames.add(elemInterfaceName);
							
							
							
								try {
									for(Method m : Class.forName(elemInterfaceUri).getMethods()) {
										if(m.getName() != "getUid" && 
												m.getName() != "setFractalComponent" && 
												m.getName() != "getFractalComponent" &&
												m.getName() != "init" &&
												m.getName() != "getUIElementItSelf" &&
												m.getName() != "getRepresentation" &&
												m.getName() != "getHTMLId" &&
												m.getName() != "getHTMLRepresentation"
											) {
											methodsToImplement += "\t@Override" + "\n";
											String parameters = "";
											Type[] parameterTypes = m.getGenericParameterTypes();
											if(parameterTypes.length > 0) {
												ArrayList<String> parametersArray = new ArrayList<String>();
												for(int j = 0; j < parameterTypes.length ; j++) {
													String[] parameterClass = parameterTypes[j].toString().split(" ");
													String parameterClassString = "";
													if(parameterClass.length > 1) {
														parameterClassString = parameterClass[1];
													} else {
														parameterClassString = parameterTypes[j].toString();
													}
													parametersArray.add(parameterClassString + " param" + j);
												}
												parameters = Resources.join(parametersArray, ",");
											}
											String[] returnClass = m.getGenericReturnType().toString().split(" ");
											String returnClassString = "";
											if(returnClass.length > 1) {
												returnClassString = returnClass[1];
											} else {
												returnClassString = m.getGenericReturnType().toString();
											}
											methodsToImplement += "\tpublic " + returnClassString + " " + m.getName() + "(" + parameters + ") {" + "\n";
											methodsToImplement += "\t\t// TODO Auto-generated method stub" + "\n";
											methodsToImplement += "\t}" + "\n";
										}
									}
								} catch (SecurityException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (ClassNotFoundException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						}
					}
				}
			} else {
				throw new Exception("Controller not found");
			}
			
			Component controllerSubstituteComponent = null;
			
			for(WebApplication wa : this.baseWebApp) {
				controllerSubstituteComponent = wa.findControllerLinkToElement(elemToSubstitute);
				if(controllerSubstituteComponent != null) {
					break;
				}
			}
			
			if(controllerSubstituteComponent != null) {
				BindingController controllerBindingitf = (BindingController)controllerSubstituteComponent.getFcInterface("binding-controller");
				
				NameController controllerNameitf = (NameController)controllerSubstituteComponent.getFcInterface("name-controller");
				String controllerComponentName = controllerNameitf.getFcName();
				
				Object[] interfacesObjects = controllerSubstituteComponent.getFcInterfaces();
				for(Object o : interfacesObjects) {
					Interface controllerInterface = (Interface) o;
					String controllerInterfaceName = (controllerInterface.getFcItfType().toString().split("/"))[0];
					//String controllerInterfaceUri = (controllerInterface.getFcItfType().toString().split("/"))[1];
					String controllerInterfaceType = (controllerInterface.getFcItfType().toString().split("/"))[2];
					if(controllerInterfaceType.equals("client")) {
						Interface elemInterface = (Interface) controllerBindingitf.lookupFc(controllerInterfaceName);
						Component elemComponent = elemInterface.getFcItfOwner();
						
						ontocompo.api.IntrospectionItf elemIi = ontocompo.api.IntrospectionItf.class.cast(elemComponent.getFcInterface("ontocompoIntrospectionItf"));
						String elemUid = elemIi.getUid();
						
						if(elemUid.equals(elemToSubstitute)) {
							if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
								String[] controllerComponentNameArray = this.bindings.get(controllerComponentName + "." + controllerInterfaceName).split("\\.");
								controllerComponentName = controllerComponentNameArray[0];
								if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
									this.bindings.remove(controllerComponentName + "." + controllerInterfaceName);
								}
							}
							String elemInterfaceName = (elemInterface.getFcItfType().toString().split("/"))[0];
							String elemInterfaceUri = (elemInterface.getFcItfType().toString().split("/"))[1];
							
							//NameController elemNameitf = (NameController)elemComponent.getFcInterface("name-controller");
							//String elemComponentName = elemNameitf.getFcName();
							
							//requiredInterfaces += "\t@Requires(name = \"" + controllerInterfaceName + "\")" + "\n";
							//requiredInterfaces += "\tprivate " + controllerInterfaceUri + " " + controllerInterfaceName + ";" + "\n\n";
							
							//this.bindings.put(adapterClassName + "Component." + controllerInterfaceName, elemComponentName + "." + elemInterfaceName);
							this.bindings.put(controllerComponentName + "." + controllerInterfaceName, adapterClassName + "Component." + elemInterfaceName);
							if(! providedInterfacesNames.contains(elemInterfaceName)) {
								providedInterfaces += ", @Interface(name = \"" + elemInterfaceName + "\", signature = " + elemInterfaceUri + ".class)";
								implementInterfaces += ", " + elemInterfaceUri;
								providedInterfacesNames.add(elemInterfaceName);
							
								try {
									for(Method m : Class.forName(elemInterfaceUri).getMethods()) {
										if(m.getName() != "getUid" && 
												m.getName() != "setFractalComponent" && 
												m.getName() != "getFractalComponent" &&
												m.getName() != "init" &&
												m.getName() != "getUIElementItSelf" &&
												m.getName() != "getRepresentation" &&
												m.getName() != "getHTMLId" &&
												m.getName() != "getHTMLRepresentation"
											) {
											methodsToImplement += "\t@Override" + "\n";
											String parameters = "";
											Type[] parameterTypes = m.getGenericParameterTypes();
											if(parameterTypes.length > 0) {
												ArrayList<String> parametersArray = new ArrayList<String>();
												for(int j = 0; j < parameterTypes.length ; j++) {
													String[] parameterClass = parameterTypes[j].toString().split(" ");
													String parameterClassString = "";
													if(parameterClass.length > 1) {
														parameterClassString = parameterClass[1];
													} else {
														parameterClassString = parameterTypes[j].toString();
													}
													parametersArray.add(parameterClassString + " param" + j);
												}
												parameters = Resources.join(parametersArray, ",");
											}
											String[] returnClass = m.getGenericReturnType().toString().split(" ");
											String returnClassString = "";
											if(returnClass.length > 1) {
												returnClassString = returnClass[1];
											} else {
												returnClassString = m.getGenericReturnType().toString();
											}
											methodsToImplement += "\tpublic " + returnClassString + " " + m.getName() + "(" + parameters + ") {" + "\n";
											methodsToImplement += "\t\t// TODO Auto-generated method stub" + "\n";
											methodsToImplement += "\t}" + "\n";
										}
									}
								} catch (SecurityException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (ClassNotFoundException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						}
					}
				}
			} else {
				throw new Exception("Controller not found");
			}
			
			String generated = this.generateAdapter(adapterClassName, providedInterfaces, implementInterfaces, requiredInterfaces, methodsToImplement);
			
			this.generatedClass.put(adapterClassName, generated);
			
			this.components.put(adapterClassName + "Component", "ontowebapp." + adapterClassName);

		} catch (NoSuchInterfaceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void output_output_substitution(String elemToKeep, String elemToSubstitute, Component componentElemToKeep, Component componentElemToSubstitute) {
		try {
			String adapterClassName = "Adapter" + Class.forName(elemToKeep).getSimpleName() + Class.forName(elemToSubstitute).getSimpleName();
			
			String providedInterfaces = "";
			ArrayList<String> providedInterfacesNames = new ArrayList<String>();
			String implementInterfaces = "ontocompo.api.IntrospectionItf";
			String requiredInterfaces = "";
			
			String methodsToImplement = "";
			
			Component controllerKeepComponent = null;
			
			for(WebApplication wa : this.baseWebApp) {
				controllerKeepComponent = wa.findControllerLinkToElement(elemToKeep);
				if(controllerKeepComponent != null) {
					break;
				}
			}
			
			if(controllerKeepComponent != null) {
				BindingController controllerBindingitf = (BindingController)controllerKeepComponent.getFcInterface("binding-controller");
				
				NameController controllerNameitf = (NameController)controllerKeepComponent.getFcInterface("name-controller");
				String controllerComponentName = controllerNameitf.getFcName();
				
				Object[] interfacesObjects = controllerKeepComponent.getFcInterfaces();
				for(Object o : interfacesObjects) {
					Interface controllerInterface = (Interface) o;
					String controllerInterfaceName = (controllerInterface.getFcItfType().toString().split("/"))[0];
					String controllerInterfaceUri = (controllerInterface.getFcItfType().toString().split("/"))[1];
					String controllerInterfaceType = (controllerInterface.getFcItfType().toString().split("/"))[2];
					
					if(controllerInterfaceType.equals("client")) {
						
						
						
						Interface elemInterface = (Interface) controllerBindingitf.lookupFc(controllerInterfaceName);
						Component elemComponent = elemInterface.getFcItfOwner();
						
						ontocompo.api.IntrospectionItf elemIi = ontocompo.api.IntrospectionItf.class.cast(elemComponent.getFcInterface("ontocompoIntrospectionItf"));
						String elemUid = elemIi.getUid();
						
						if(elemUid.equals(elemToKeep)) {
							if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
								String[] controllerComponentNameArray = this.bindings.get(controllerComponentName + "." + controllerInterfaceName).split("\\.");
								controllerComponentName = controllerComponentNameArray[0];
								if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
									this.bindings.remove(controllerComponentName + "." + controllerInterfaceName);
								}
							}
							
							String elemInterfaceName = (elemInterface.getFcItfType().toString().split("/"))[0];
							String elemInterfaceUri = (elemInterface.getFcItfType().toString().split("/"))[1];
							
							NameController elemNameitf = (NameController)elemComponent.getFcInterface("name-controller");
							String elemComponentName = elemNameitf.getFcName();
							
							requiredInterfaces += "\t@Requires(name = \"" + controllerInterfaceName + "\")" + "\n";
							requiredInterfaces += "\tprivate " + controllerInterfaceUri + " " + controllerInterfaceName + ";" + "\n\n";
							
							this.bindings.put(adapterClassName + "Component." + controllerInterfaceName, elemComponentName + "." + elemInterfaceName);
							this.bindings.put(controllerComponentName + "." + controllerInterfaceName, adapterClassName + "Component." + elemInterfaceName);
							if(! providedInterfacesNames.contains(elemInterfaceName)) {
								providedInterfaces += ", @Interface(name = \"" + elemInterfaceName + "\", signature = " + elemInterfaceUri + ".class)";
								implementInterfaces += ", " + elemInterfaceUri;
								providedInterfacesNames.add(elemInterfaceName);
							
							
							
								try {
									for(Method m : Class.forName(elemInterfaceUri).getMethods()) {
										if(m.getName() != "getUid" && 
												m.getName() != "setFractalComponent" && 
												m.getName() != "getFractalComponent" &&
												m.getName() != "init" &&
												m.getName() != "getUIElementItSelf" &&
												m.getName() != "getRepresentation" &&
												m.getName() != "getHTMLId" &&
												m.getName() != "getHTMLRepresentation"
											) {
											methodsToImplement += "\t@Override" + "\n";
											String parameters = "";
											Type[] parameterTypes = m.getGenericParameterTypes();
											if(parameterTypes.length > 0) {
												ArrayList<String> parametersArray = new ArrayList<String>();
												for(int j = 0; j < parameterTypes.length ; j++) {
													String[] parameterClass = parameterTypes[j].toString().split(" ");
													String parameterClassString = "";
													if(parameterClass.length > 1) {
														parameterClassString = parameterClass[1];
													} else {
														parameterClassString = parameterTypes[j].toString();
													}
													parametersArray.add(parameterClassString + " param" + j);
												}
												parameters = Resources.join(parametersArray, ",");
											}
											String[] returnClass = m.getGenericReturnType().toString().split(" ");
											String returnClassString = "";
											if(returnClass.length > 1) {
												returnClassString = returnClass[1];
											} else {
												returnClassString = m.getGenericReturnType().toString();
											}
											methodsToImplement += "\tpublic " + returnClassString + " " + m.getName() + "(" + parameters + ") {" + "\n";
											methodsToImplement += "\t\t// TODO Auto-generated method stub" + "\n";
											methodsToImplement += "\t}" + "\n";
										}
									}
								} catch (SecurityException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (ClassNotFoundException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						}
					}
				}
			} else {
				throw new Exception("Controller not found");
			}
			
			Component controllerSubstituteComponent = null;
			
			for(WebApplication wa : this.baseWebApp) {
				controllerSubstituteComponent = wa.findControllerLinkToElement(elemToSubstitute);
				if(controllerSubstituteComponent != null) {
					break;
				}
			}
			
			if(controllerSubstituteComponent != null) {
				BindingController controllerBindingitf = (BindingController)controllerSubstituteComponent.getFcInterface("binding-controller");
				
				NameController controllerNameitf = (NameController)controllerSubstituteComponent.getFcInterface("name-controller");
				String controllerComponentName = controllerNameitf.getFcName();
				
				Object[] interfacesObjects = controllerSubstituteComponent.getFcInterfaces();
				for(Object o : interfacesObjects) {
					Interface controllerInterface = (Interface) o;
					String controllerInterfaceName = (controllerInterface.getFcItfType().toString().split("/"))[0];
					//String controllerInterfaceUri = (controllerInterface.getFcItfType().toString().split("/"))[1];
					String controllerInterfaceType = (controllerInterface.getFcItfType().toString().split("/"))[2];
					if(controllerInterfaceType.equals("client")) {
						
						Interface elemInterface = (Interface) controllerBindingitf.lookupFc(controllerInterfaceName);
						Component elemComponent = elemInterface.getFcItfOwner();
						
						ontocompo.api.IntrospectionItf elemIi = ontocompo.api.IntrospectionItf.class.cast(elemComponent.getFcInterface("ontocompoIntrospectionItf"));
						String elemUid = elemIi.getUid();
						
						if(elemUid.equals(elemToSubstitute)) {
							if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
								String[] controllerComponentNameArray = this.bindings.get(controllerComponentName + "." + controllerInterfaceName).split("\\.");
								controllerComponentName = controllerComponentNameArray[0];
								if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
									this.bindings.remove(controllerComponentName + "." + controllerInterfaceName);
								}
							}
							
							String elemInterfaceName = (elemInterface.getFcItfType().toString().split("/"))[0];
							String elemInterfaceUri = (elemInterface.getFcItfType().toString().split("/"))[1];
							
							//NameController elemNameitf = (NameController)elemComponent.getFcInterface("name-controller");
							//String elemComponentName = elemNameitf.getFcName();
							
							//requiredInterfaces += "\t@Requires(name = \"" + controllerInterfaceName + "\")" + "\n";
							//requiredInterfaces += "\tprivate " + controllerInterfaceUri + " " + controllerInterfaceName + ";" + "\n\n";
							
							//this.bindings.put(adapterClassName + "Component." + controllerInterfaceName, elemComponentName + "." + elemInterfaceName);
							this.bindings.put(controllerComponentName + "." + controllerInterfaceName, adapterClassName + "Component." + elemInterfaceName);
							if(! providedInterfacesNames.contains(elemInterfaceName)) {
								providedInterfaces += ", @Interface(name = \"" + elemInterfaceName + "\", signature = " + elemInterfaceUri + ".class)";
								implementInterfaces += ", " + elemInterfaceUri;
								providedInterfacesNames.add(elemInterfaceName);
							
								try {
									for(Method m : Class.forName(elemInterfaceUri).getMethods()) {
										if(m.getName() != "getUid" && 
												m.getName() != "setFractalComponent" && 
												m.getName() != "getFractalComponent" &&
												m.getName() != "init" &&
												m.getName() != "getUIElementItSelf" &&
												m.getName() != "getRepresentation" &&
												m.getName() != "getHTMLId" &&
												m.getName() != "getHTMLRepresentation"
											) {
											methodsToImplement += "\t@Override" + "\n";
											String parameters = "";
											Type[] parameterTypes = m.getGenericParameterTypes();
											if(parameterTypes.length > 0) {
												ArrayList<String> parametersArray = new ArrayList<String>();
												for(int j = 0; j < parameterTypes.length ; j++) {
													String[] parameterClass = parameterTypes[j].toString().split(" ");
													String parameterClassString = "";
													if(parameterClass.length > 1) {
														parameterClassString = parameterClass[1];
													} else {
														parameterClassString = parameterTypes[j].toString();
													}
													parametersArray.add(parameterClassString + " param" + j);
												}
												parameters = Resources.join(parametersArray, ",");
											}
											String[] returnClass = m.getGenericReturnType().toString().split(" ");
											String returnClassString = "";
											if(returnClass.length > 1) {
												returnClassString = returnClass[1];
											} else {
												returnClassString = m.getGenericReturnType().toString();
											}
											methodsToImplement += "\tpublic " + returnClassString + " " + m.getName() + "(" + parameters + ") {" + "\n";
											methodsToImplement += "\t\t// TODO Auto-generated method stub" + "\n";
											methodsToImplement += "\t}" + "\n";
										}
									}
								} catch (SecurityException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (ClassNotFoundException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						}
					}
				}
			} else {
				throw new Exception("Controller not found");
			}
			
			String generated = this.generateAdapter(adapterClassName, providedInterfaces, implementInterfaces, requiredInterfaces, methodsToImplement);
			
			this.generatedClass.put(adapterClassName, generated);
			
			this.components.put(adapterClassName + "Component", "ontowebapp." + adapterClassName);

		} catch (NoSuchInterfaceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void output_input_substitution(String elemToKeep, String elemToSubstitute, Component componentElemToKeep, Component componentElemToSubstitute) {
		try {
			String adapterClassName = "Adapter" + Class.forName(elemToKeep).getSimpleName() + Class.forName(elemToSubstitute).getSimpleName();
			
			String providedInterfaces = "";
			ArrayList<String> providedInterfacesNames = new ArrayList<String>();
			String implementInterfaces = "ontocompo.api.IntrospectionItf";
			String requiredInterfaces = "";
			
			String methodsToImplement = "";
			
			Component controllerKeepComponent = null;
			
			for(WebApplication wa : this.baseWebApp) {
				controllerKeepComponent = wa.findControllerLinkToElement(elemToKeep);
				if(controllerKeepComponent != null) {
					break;
				}
			}
			
			if(controllerKeepComponent != null) {
				BindingController controllerBindingitf = (BindingController)controllerKeepComponent.getFcInterface("binding-controller");
				
				NameController controllerNameitf = (NameController)controllerKeepComponent.getFcInterface("name-controller");
				String controllerComponentName = controllerNameitf.getFcName();
				
				Object[] interfacesObjects = controllerKeepComponent.getFcInterfaces();
				for(Object o : interfacesObjects) {
					Interface controllerInterface = (Interface) o;
					String controllerInterfaceName = (controllerInterface.getFcItfType().toString().split("/"))[0];
					String controllerInterfaceUri = (controllerInterface.getFcItfType().toString().split("/"))[1];
					String controllerInterfaceType = (controllerInterface.getFcItfType().toString().split("/"))[2];
					
					if(controllerInterfaceType.equals("client")) {
						if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
							String[] controllerComponentNameArray = this.bindings.get(controllerComponentName + "." + controllerInterfaceName).split("\\.");
							controllerComponentName = controllerComponentNameArray[0];
							if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
								this.bindings.remove(controllerComponentName + "." + controllerInterfaceName);
							}
						}
						
						Interface elemInterface = (Interface) controllerBindingitf.lookupFc(controllerInterfaceName);
						Component elemComponent = elemInterface.getFcItfOwner();
						
						ontocompo.api.IntrospectionItf elemIi = ontocompo.api.IntrospectionItf.class.cast(elemComponent.getFcInterface("ontocompoIntrospectionItf"));
						String elemUid = elemIi.getUid();
						
						if(elemUid.equals(elemToKeep)) {
							String elemInterfaceName = (elemInterface.getFcItfType().toString().split("/"))[0];
							String elemInterfaceUri = (elemInterface.getFcItfType().toString().split("/"))[1];
							
							NameController elemNameitf = (NameController)elemComponent.getFcInterface("name-controller");
							String elemComponentName = elemNameitf.getFcName();
							
							requiredInterfaces += "\t@Requires(name = \"" + controllerInterfaceName + "\")" + "\n";
							requiredInterfaces += "\tprivate " + controllerInterfaceUri + " " + controllerInterfaceName + ";" + "\n\n";
							
							this.bindings.put(adapterClassName + "Component." + controllerInterfaceName, elemComponentName + "." + elemInterfaceName);
							this.bindings.put(controllerComponentName + "." + controllerInterfaceName, adapterClassName + "Component." + elemInterfaceName);
							if(! providedInterfacesNames.contains(elemInterfaceName)) {
								providedInterfaces += ", @Interface(name = \"" + elemInterfaceName + "\", signature = " + elemInterfaceUri + ".class)";
								implementInterfaces += ", " + elemInterfaceUri;
								providedInterfacesNames.add(elemInterfaceName);
							
							
							
								try {
									for(Method m : Class.forName(elemInterfaceUri).getMethods()) {
										if(m.getName() != "getUid" && 
												m.getName() != "setFractalComponent" && 
												m.getName() != "getFractalComponent" &&
												m.getName() != "init" &&
												m.getName() != "getUIElementItSelf" &&
												m.getName() != "getRepresentation" &&
												m.getName() != "getHTMLId" &&
												m.getName() != "getHTMLRepresentation"
											) {
											methodsToImplement += "\t@Override" + "\n";
											String parameters = "";
											Type[] parameterTypes = m.getGenericParameterTypes();
											if(parameterTypes.length > 0) {
												ArrayList<String> parametersArray = new ArrayList<String>();
												for(int j = 0; j < parameterTypes.length ; j++) {
													String[] parameterClass = parameterTypes[j].toString().split(" ");
													String parameterClassString = "";
													if(parameterClass.length > 1) {
														parameterClassString = parameterClass[1];
													} else {
														parameterClassString = parameterTypes[j].toString();
													}
													parametersArray.add(parameterClassString + " param" + j);
												}
												parameters = Resources.join(parametersArray, ",");
											}
											String[] returnClass = m.getGenericReturnType().toString().split(" ");
											String returnClassString = "";
											if(returnClass.length > 1) {
												returnClassString = returnClass[1];
											} else {
												returnClassString = m.getGenericReturnType().toString();
											}
											methodsToImplement += "\tpublic " + returnClassString + " " + m.getName() + "(" + parameters + ") {" + "\n";
											methodsToImplement += "\t\t// TODO Auto-generated method stub" + "\n";
											methodsToImplement += "\t}" + "\n";
										}
									}
								} catch (SecurityException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (ClassNotFoundException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						}
					}
				}
			} else {
				throw new Exception("Controller not found");
			}
			
			Component controllerSubstituteComponent = null;
			
			for(WebApplication wa : this.baseWebApp) {
				controllerSubstituteComponent = wa.findControllerLinkToElement(elemToSubstitute);
				if(controllerSubstituteComponent != null) {
					break;
				}
			}
			
			if(controllerSubstituteComponent != null) {
				BindingController controllerBindingitf = (BindingController)controllerSubstituteComponent.getFcInterface("binding-controller");
				
				NameController controllerNameitf = (NameController)controllerSubstituteComponent.getFcInterface("name-controller");
				String controllerComponentName = controllerNameitf.getFcName();
				
				Object[] interfacesObjects = controllerSubstituteComponent.getFcInterfaces();
				for(Object o : interfacesObjects) {
					Interface controllerInterface = (Interface) o;
					String controllerInterfaceName = (controllerInterface.getFcItfType().toString().split("/"))[0];
					//String controllerInterfaceUri = (controllerInterface.getFcItfType().toString().split("/"))[1];
					String controllerInterfaceType = (controllerInterface.getFcItfType().toString().split("/"))[2];
					if(controllerInterfaceType.equals("client")) {
						
						Interface elemInterface = (Interface) controllerBindingitf.lookupFc(controllerInterfaceName);
						Component elemComponent = elemInterface.getFcItfOwner();
						
						ontocompo.api.IntrospectionItf elemIi = ontocompo.api.IntrospectionItf.class.cast(elemComponent.getFcInterface("ontocompoIntrospectionItf"));
						String elemUid = elemIi.getUid();
						
						if(elemUid.equals(elemToSubstitute)) {
							if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
								String[] controllerComponentNameArray = this.bindings.get(controllerComponentName + "." + controllerInterfaceName).split("\\.");
								controllerComponentName = controllerComponentNameArray[0];
								if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
									this.bindings.remove(controllerComponentName + "." + controllerInterfaceName);
								}
							}
							String elemInterfaceName = (elemInterface.getFcItfType().toString().split("/"))[0];
							String elemInterfaceUri = (elemInterface.getFcItfType().toString().split("/"))[1];
							
							//NameController elemNameitf = (NameController)elemComponent.getFcInterface("name-controller");
							//String elemComponentName = elemNameitf.getFcName();
							
							//requiredInterfaces += "\t@Requires(name = \"" + controllerInterfaceName + "\")" + "\n";
							//requiredInterfaces += "\tprivate " + controllerInterfaceUri + " " + controllerInterfaceName + ";" + "\n\n";
							
							//this.bindings.put(adapterClassName + "Component." + controllerInterfaceName, elemComponentName + "." + elemInterfaceName);
							this.bindings.put(controllerComponentName + "." + controllerInterfaceName, adapterClassName + "Component." + elemInterfaceName);
							if(! providedInterfacesNames.contains(elemInterfaceName)) {
								providedInterfaces += ", @Interface(name = \"" + elemInterfaceName + "\", signature = " + elemInterfaceUri + ".class)";
								implementInterfaces += ", " + elemInterfaceUri;
								providedInterfacesNames.add(elemInterfaceName);
							
								try {
									for(Method m : Class.forName(elemInterfaceUri).getMethods()) {
										if(m.getName() != "getUid" && 
												m.getName() != "setFractalComponent" && 
												m.getName() != "getFractalComponent" &&
												m.getName() != "init" &&
												m.getName() != "getUIElementItSelf" &&
												m.getName() != "getRepresentation" &&
												m.getName() != "getHTMLId" &&
												m.getName() != "getHTMLRepresentation"
											) {
											methodsToImplement += "\t@Override" + "\n";
											String parameters = "";
											Type[] parameterTypes = m.getGenericParameterTypes();
											if(parameterTypes.length > 0) {
												ArrayList<String> parametersArray = new ArrayList<String>();
												for(int j = 0; j < parameterTypes.length ; j++) {
													String[] parameterClass = parameterTypes[j].toString().split(" ");
													String parameterClassString = "";
													if(parameterClass.length > 1) {
														parameterClassString = parameterClass[1];
													} else {
														parameterClassString = parameterTypes[j].toString();
													}
													parametersArray.add(parameterClassString + " param" + j);
												}
												parameters = Resources.join(parametersArray, ",");
											}
											String[] returnClass = m.getGenericReturnType().toString().split(" ");
											String returnClassString = "";
											if(returnClass.length > 1) {
												returnClassString = returnClass[1];
											} else {
												returnClassString = m.getGenericReturnType().toString();
											}
											methodsToImplement += "\tpublic " + returnClassString + " " + m.getName() + "(" + parameters + ") {" + "\n";
											methodsToImplement += "\t\t// TODO Auto-generated method stub" + "\n";
											methodsToImplement += "\t}" + "\n";
										}
									}
								} catch (SecurityException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (ClassNotFoundException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						}
					}
				}
			} else {
				throw new Exception("Controller not found");
			}
			
			String generated = this.generateAdapter(adapterClassName, providedInterfaces, implementInterfaces, requiredInterfaces, methodsToImplement);
			
			this.generatedClass.put(adapterClassName, generated);
			
			this.components.put(adapterClassName + "Component", "ontowebapp." + adapterClassName);

		} catch (NoSuchInterfaceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void input_output_substitution(String elemToKeep, String elemToSubstitute, Component componentElemToKeep, Component componentElemToSubstitute) {
		try {
			String adapterClassName = "Adapter" + Class.forName(elemToKeep).getSimpleName() + Class.forName(elemToSubstitute).getSimpleName();
			
			String providedInterfaces = "";
			ArrayList<String> providedInterfacesNames = new ArrayList<String>();
			String implementInterfaces = "ontocompo.api.IntrospectionItf";
			String requiredInterfaces = "";
			
			String methodsToImplement = "";
			
			Component controllerKeepComponent = null;
			
			for(WebApplication wa : this.baseWebApp) {
				controllerKeepComponent = wa.findControllerLinkToElement(elemToKeep);
				if(controllerKeepComponent != null) {
					break;
				}
			}
			
			if(controllerKeepComponent != null) {
				BindingController controllerBindingitf = (BindingController)controllerKeepComponent.getFcInterface("binding-controller");
				
				NameController controllerNameitf = (NameController)controllerKeepComponent.getFcInterface("name-controller");
				String controllerComponentName = controllerNameitf.getFcName();
				
				Object[] interfacesObjects = controllerKeepComponent.getFcInterfaces();
				for(Object o : interfacesObjects) {
					Interface controllerInterface = (Interface) o;
					String controllerInterfaceName = (controllerInterface.getFcItfType().toString().split("/"))[0];
					String controllerInterfaceUri = (controllerInterface.getFcItfType().toString().split("/"))[1];
					String controllerInterfaceType = (controllerInterface.getFcItfType().toString().split("/"))[2];
					
					if(controllerInterfaceType.equals("client")) {
						Interface elemInterface = (Interface) controllerBindingitf.lookupFc(controllerInterfaceName);
						Component elemComponent = elemInterface.getFcItfOwner();
						
						ontocompo.api.IntrospectionItf elemIi = ontocompo.api.IntrospectionItf.class.cast(elemComponent.getFcInterface("ontocompoIntrospectionItf"));
						String elemUid = elemIi.getUid();
						
						if(elemUid.equals(elemToKeep)) {
							if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
								String[] controllerComponentNameArray = this.bindings.get(controllerComponentName + "." + controllerInterfaceName).split("\\.");
								controllerComponentName = controllerComponentNameArray[0];
								if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
									this.bindings.remove(controllerComponentName + "." + controllerInterfaceName);
								}
							}
							
							String elemInterfaceName = (elemInterface.getFcItfType().toString().split("/"))[0];
							String elemInterfaceUri = (elemInterface.getFcItfType().toString().split("/"))[1];
							
							NameController elemNameitf = (NameController)elemComponent.getFcInterface("name-controller");
							String elemComponentName = elemNameitf.getFcName();
							
							requiredInterfaces += "\t@Requires(name = \"" + controllerInterfaceName + "\")" + "\n";
							requiredInterfaces += "\tprivate " + controllerInterfaceUri + " " + controllerInterfaceName + ";" + "\n\n";
							
							this.bindings.put(adapterClassName + "Component." + controllerInterfaceName, elemComponentName + "." + elemInterfaceName);
							this.bindings.put(controllerComponentName + "." + controllerInterfaceName, adapterClassName + "Component." + elemInterfaceName);
							if(! providedInterfacesNames.contains(elemInterfaceName)) {
								providedInterfaces += ", @Interface(name = \"" + elemInterfaceName + "\", signature = " + elemInterfaceUri + ".class)";
								implementInterfaces += ", " + elemInterfaceUri;
								providedInterfacesNames.add(elemInterfaceName);
							
							
							
								try {
									for(Method m : Class.forName(elemInterfaceUri).getMethods()) {
										if(m.getName() != "getUid" && 
												m.getName() != "setFractalComponent" && 
												m.getName() != "getFractalComponent" &&
												m.getName() != "init" &&
												m.getName() != "getUIElementItSelf" &&
												m.getName() != "getRepresentation" &&
												m.getName() != "getHTMLId" &&
												m.getName() != "getHTMLRepresentation"
											) {
											methodsToImplement += "\t@Override" + "\n";
											String parameters = "";
											Type[] parameterTypes = m.getGenericParameterTypes();
											if(parameterTypes.length > 0) {
												ArrayList<String> parametersArray = new ArrayList<String>();
												for(int j = 0; j < parameterTypes.length ; j++) {
													String[] parameterClass = parameterTypes[j].toString().split(" ");
													String parameterClassString = "";
													if(parameterClass.length > 1) {
														parameterClassString = parameterClass[1];
													} else {
														parameterClassString = parameterTypes[j].toString();
													}
													parametersArray.add(parameterClassString + " param" + j);
												}
												parameters = Resources.join(parametersArray, ",");
											}
											String[] returnClass = m.getGenericReturnType().toString().split(" ");
											String returnClassString = "";
											if(returnClass.length > 1) {
												returnClassString = returnClass[1];
											} else {
												returnClassString = m.getGenericReturnType().toString();
											}
											methodsToImplement += "\tpublic " + returnClassString + " " + m.getName() + "(" + parameters + ") {" + "\n";
											methodsToImplement += "\t\t// TODO Auto-generated method stub" + "\n";
											methodsToImplement += "\t}" + "\n";
										}
									}
								} catch (SecurityException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (ClassNotFoundException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						}
					}
				}
			} else {
				throw new Exception("Controller not found");
			}
			
			Component controllerSubstituteComponent = null;
			
			for(WebApplication wa : this.baseWebApp) {
				controllerSubstituteComponent = wa.findControllerLinkToElement(elemToSubstitute);
				if(controllerSubstituteComponent != null) {
					break;
				}
			}
			
			if(controllerSubstituteComponent != null) {
				BindingController controllerBindingitf = (BindingController)controllerSubstituteComponent.getFcInterface("binding-controller");
				
				NameController controllerNameitf = (NameController)controllerSubstituteComponent.getFcInterface("name-controller");
				String controllerComponentName = controllerNameitf.getFcName();
				
				Object[] interfacesObjects = controllerSubstituteComponent.getFcInterfaces();
				for(Object o : interfacesObjects) {
					Interface controllerInterface = (Interface) o;
					String controllerInterfaceName = (controllerInterface.getFcItfType().toString().split("/"))[0];
					//String controllerInterfaceUri = (controllerInterface.getFcItfType().toString().split("/"))[1];
					String controllerInterfaceType = (controllerInterface.getFcItfType().toString().split("/"))[2];
					if(controllerInterfaceType.equals("client")) {
						
						Interface elemInterface = (Interface) controllerBindingitf.lookupFc(controllerInterfaceName);
						Component elemComponent = elemInterface.getFcItfOwner();
						
						ontocompo.api.IntrospectionItf elemIi = ontocompo.api.IntrospectionItf.class.cast(elemComponent.getFcInterface("ontocompoIntrospectionItf"));
						String elemUid = elemIi.getUid();
						
						if(elemUid.equals(elemToSubstitute)) {
							if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
								String[] controllerComponentNameArray = this.bindings.get(controllerComponentName + "." + controllerInterfaceName).split("\\.");
								controllerComponentName = controllerComponentNameArray[0];
								if(this.bindings.containsKey(controllerComponentName + "." + controllerInterfaceName)) {
									this.bindings.remove(controllerComponentName + "." + controllerInterfaceName);
								}
							}
							String elemInterfaceName = (elemInterface.getFcItfType().toString().split("/"))[0];
							String elemInterfaceUri = (elemInterface.getFcItfType().toString().split("/"))[1];
							
							//NameController elemNameitf = (NameController)elemComponent.getFcInterface("name-controller");
							//String elemComponentName = elemNameitf.getFcName();
							
							//requiredInterfaces += "\t@Requires(name = \"" + controllerInterfaceName + "\")" + "\n";
							//requiredInterfaces += "\tprivate " + controllerInterfaceUri + " " + controllerInterfaceName + ";" + "\n\n";
							
							//this.bindings.put(adapterClassName + "Component." + controllerInterfaceName, elemComponentName + "." + elemInterfaceName);
							this.bindings.put(controllerComponentName + "." + controllerInterfaceName, adapterClassName + "Component." + elemInterfaceName);
							if(! providedInterfacesNames.contains(elemInterfaceName)) {
								providedInterfaces += ", @Interface(name = \"" + elemInterfaceName + "\", signature = " + elemInterfaceUri + ".class)";
								implementInterfaces += ", " + elemInterfaceUri;
								providedInterfacesNames.add(elemInterfaceName);
							
								try {
									for(Method m : Class.forName(elemInterfaceUri).getMethods()) {
										if(m.getName() != "getUid" && 
												m.getName() != "setFractalComponent" && 
												m.getName() != "getFractalComponent" &&
												m.getName() != "init" &&
												m.getName() != "getUIElementItSelf" &&
												m.getName() != "getRepresentation" &&
												m.getName() != "getHTMLId" &&
												m.getName() != "getHTMLRepresentation"
											) {
											methodsToImplement += "\t@Override" + "\n";
											String parameters = "";
											Type[] parameterTypes = m.getGenericParameterTypes();
											if(parameterTypes.length > 0) {
												ArrayList<String> parametersArray = new ArrayList<String>();
												for(int j = 0; j < parameterTypes.length ; j++) {
													String[] parameterClass = parameterTypes[j].toString().split(" ");
													String parameterClassString = "";
													if(parameterClass.length > 1) {
														parameterClassString = parameterClass[1];
													} else {
														parameterClassString = parameterTypes[j].toString();
													}
													parametersArray.add(parameterClassString + " param" + j);
												}
												parameters = Resources.join(parametersArray, ",");
											}
											String[] returnClass = m.getGenericReturnType().toString().split(" ");
											String returnClassString = "";
											if(returnClass.length > 1) {
												returnClassString = returnClass[1];
											} else {
												returnClassString = m.getGenericReturnType().toString();
											}
											methodsToImplement += "\tpublic " + returnClassString + " " + m.getName() + "(" + parameters + ") {" + "\n";
											methodsToImplement += "\t\t// TODO Auto-generated method stub" + "\n";
											methodsToImplement += "\t}" + "\n";
										}
									}
								} catch (SecurityException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (ClassNotFoundException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						}
					}
				}
			} else {
				throw new Exception("Controller not found");
			}
			
			String generated = this.generateAdapter(adapterClassName, providedInterfaces, implementInterfaces, requiredInterfaces, methodsToImplement);
			
			this.generatedClass.put(adapterClassName, generated);
			
			this.components.put(adapterClassName + "Component", "ontowebapp." + adapterClassName);

		} catch (NoSuchInterfaceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public String generateAdapter(String adapterClassName, String providedInterfaces, String implementInterfaces, String requiredInterfaces, String methodsToImplement) {
		String generated = "package ontowebapp;" + "\n";
		generated += "" + "\n";
		generated += "import org.objectweb.fractal.fraclet.annotations.Component;" + "\n";
		generated += "import org.objectweb.fractal.fraclet.annotations.Interface;" + "\n";
		generated += "import org.objectweb.fractal.fraclet.annotations.Requires;" + "\n";
		generated += "" + "\n";
		generated += "@Component(provides = {";
		generated += "@Interface(name = \"ontocompoIntrospectionItf\", signature = ontocompo.api.IntrospectionItf.class)";
		generated += providedInterfaces;
		generated += "})" + "\n";
		generated += "public class " + adapterClassName + " extends ontocompo.adapter.lib.Adapter implements " + implementInterfaces + " {" + "\n";
		generated += "" + "\n";
		generated += requiredInterfaces;
		generated += "" + "\n";
		generated += "\tpublic " + adapterClassName + "() {" + "\n";
		generated += "\t\tthis.uid = \"ontowebapp." + adapterClassName + "\";" + "\n";
		generated += "\t}" + "\n";
		generated += "" + "\n";
		generated += methodsToImplement;
		generated += "" + "\n";
		generated += "}" + "\n";
		
		return generated;
	}
	
	public void generateComposedApplication() {
		/* Begin: Get All Informations for new Fractal Application */
		
		for(WebApplication wa : this.baseWebApp) {
			ArrayList<UIElementItf> selectedElementsWithoutContainer = wa.getSelectedUIElementsIdsAndHtml();
			for(UIElementItf uiei : selectedElementsWithoutContainer) {
				try {
					Component elemCompo = wa.getElementComponent(uiei.getId());
					
					NameController elemNameItf = (NameController) elemCompo.getFcInterface("name-controller");
					String elemName = elemNameItf.getFcName();
					
					ontocompo.api.IntrospectionItf elemIi = ontocompo.api.IntrospectionItf.class.cast(elemCompo.getFcInterface("ontocompoIntrospectionItf"));
					String elemUid = elemIi.getUid();
					
					BindingController bindingitf = (BindingController)elemCompo.getFcInterface("binding-controller");
					String[] interfaces = bindingitf.listFc();
					
					for(String i: interfaces) {
						Interface elemInterface = (Interface) elemCompo.getFcInterface(i);
						String interfaceName = (elemInterface.getFcItfType().toString().split("/"))[0];
						String interfaceUri = (elemInterface.getFcItfType().toString().split("/"))[1];
						
						if(ontocompo.control.api.ControllerItf.class.getName().equals(interfaceUri)) {
							Object o = bindingitf.lookupFc(i);
							Interface itfserver = (Interface) o;
							String itfserverName = (itfserver.getFcItfType().toString().split("/"))[0];
							//String itfserverUri = (itfserver.getFcItfType().toString().split("/"))[1];
							Component cserver = itfserver.getFcItfOwner();
							
							ontocompo.api.IntrospectionItf ii = ontocompo.api.IntrospectionItf.class.cast(cserver.getFcInterface("ontocompoIntrospectionItf"));
							String uid = ii.getUid();
							
							NameController nameItf = (NameController) cserver.getFcInterface("name-controller");
							String name = nameItf.getFcName();
							if(! this.components.containsKey(name)) {
								this.components.put(name, uid);
								
								BindingController controllerBindingitf = (BindingController)cserver.getFcInterface("binding-controller");
								String[] controllerInterfaces = controllerBindingitf.listFc();
								for(String controllerI : controllerInterfaces) {
									Interface controlInterface = (Interface) cserver.getFcInterface(controllerI);
									String controlInterfaceName = (controlInterface.getFcItfType().toString().split("/"))[0];
									String controlInterfaceUri = (controlInterface.getFcItfType().toString().split("/"))[1];
									
									if(ontocompo.fc.api.ServiceItf.class.isAssignableFrom(Class.forName(controlInterfaceUri))) {
										Object serviceO = controllerBindingitf.lookupFc(controllerI);
										Interface serviceInterface = (Interface) serviceO;
										String serviceInterfaceName = (serviceInterface.getFcItfType().toString().split("/"))[0];
										//String serviceInterfaceUri = (serviceInterface.getFcItfType().toString().split("/"))[1];
										Component serviceComponent = serviceInterface.getFcItfOwner();
										
										ontocompo.api.IntrospectionItf serviceIi = ontocompo.api.IntrospectionItf.class.cast(serviceComponent.getFcInterface("ontocompoIntrospectionItf"));
										String serviceUid = serviceIi.getUid();
										
										NameController serviceNameItf = (NameController) serviceComponent.getFcInterface("name-controller");
										String serviceName = serviceNameItf.getFcName();
										
										if(! this.components.containsKey(serviceName)) {
											this.components.put(serviceName, serviceUid);
											if(! this.bindings.containsKey(name + "." +  controlInterfaceName)) {
												this.bindings.put(name + "." +  controlInterfaceName, serviceName + "." + serviceInterfaceName);
											}
										}
									} else {
										Object elemO = controllerBindingitf.lookupFc(controllerI);
										Interface elemServerInterface = (Interface) elemO;
										String elemInterfaceName = (elemServerInterface.getFcItfType().toString().split("/"))[0];
										//String elemInterfaceUri = (elemServerInterface.getFcItfType().toString().split("/"))[1];
										Component elemServerComponent = elemServerInterface.getFcItfOwner();
										
										NameController serviceNameItf = (NameController) elemServerComponent.getFcInterface("name-controller");
										String serviceName = serviceNameItf.getFcName();
										
										if(this.components.containsKey(serviceName)) {
											if(! this.bindings.containsKey(name + "." +  controlInterfaceName)) {
												this.bindings.put(name + "." +  controlInterfaceName, serviceName + "." + elemInterfaceName);
											}
										} else {
											ontocompo.api.IntrospectionItf elemServerIi = ontocompo.api.IntrospectionItf.class.cast(elemServerComponent.getFcInterface("ontocompoIntrospectionItf"));
											String elemServerUid = elemServerIi.getUid();
											
											if(wa.getSelectedUIElements().containsKey(elemServerUid)) {
												if(! this.bindings.containsKey(name + "." +  controlInterfaceName)) {
													this.bindings.put(name + "." +  controlInterfaceName, serviceName + "." + elemInterfaceName);
												}
											}
										}
									}
								}
							}
							
							if(! this.bindings.containsKey(elemName + "." + interfaceName)) {
								this.bindings.put(elemName + "." + interfaceName, name + "." + itfserverName);
							}
						}
					}
					this.components.put(elemName, elemUid);
					
				} catch (RemoteException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (NoSuchInterfaceException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		ArrayList<String> keysTemp = new ArrayList<String>();
		for(String client : this.bindings.keySet()) {
			keysTemp.add(client);
		}
		
		for(String client : keysTemp) {
			String[] clientArray = client.split("\\.");
			String clientComponentName = clientArray[0];
			
			if(! this.components.containsKey(clientComponentName)) {
				this.findAndAdd(clientComponentName);
			}
			
			String[] serverArray = this.bindings.get(client).split("\\.");
			String serverComponentName = serverArray[0];
			
			if(! this.components.containsKey(serverComponentName)) {
				this.findAndAdd(serverComponentName);
			}
		}
		
		/* End: Get All Informations for new Fractal Application */
		
		this.generatedClass.put("IndexScreenContainer", this.generateContainer("IndexScreenContainer", this.appName + "ScreenContainer"));
		this.components.put("IndexScreenContainerComponent", "ontowebapp.IndexScreenContainer");
		
		this.generatedClass.put("IndexScreen", this.generateScreen("IndexScreen", this.appName + "Screen"));
		this.components.put("IndexScreenComponent", "ontowebapp.IndexScreen");
		
		this.bindings.put("IndexScreenComponent.indexScreenContainer_html", "IndexScreenContainerComponent.htmlContainerItf");
		
		this.bindings.put("this.htmlEntryPoint", "IndexScreenComponent.htmlScreenItf");
		
		for(String fileName : this.generatedClass.keySet()) {
			this.writeGeneratedFile(fileName + ".java", this.generatedClass.get(fileName));
		}
		
		this.writeGeneratedFile(this.appName + "App.fractal", this.generateFractalFile());
		
		this.writeGeneratedFile("generatedapp.ontoapp", this.generateOntoappDescriptionFile());
	}
	
	public String generateOntoappDescriptionFile() {
		String generated = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n";
		generated += "<ontoapp>" + "\n";
		generated += "\t<name><![CDATA[Generated Application]]></name>" + "\n";
		generated += "\t<appid><![CDATA[ontowebapp." + this.appName +  "App]]></appid>" + "\n";
		generated += "\t<appdir><![CDATA[semantic/applications/generatedapp/]]></appdir>" + "\n";
		generated += "\t<ontographname><![CDATA[http://rainbow.i3s.unice.fr/applications/generatedapp]]></ontographname>" + "\n";
		generated += "</ontoapp>" + "\n";
			
		return generated;
	}
	
	public void findAndAdd(String clientComponentName) {
		Component c = this.findComponent(clientComponentName);
		
		try {
			ontocompo.api.IntrospectionItf cIi = ontocompo.api.IntrospectionItf.class.cast(c.getFcInterface("ontocompoIntrospectionItf"));
			String cUid = cIi.getUid();
			
			if(cUid != null) {
				this.components.put(clientComponentName, cUid);
			}
			
			NameController nameItf = (NameController) c.getFcInterface("name-controller");
			String name = nameItf.getFcName();
			
			BindingController controllerBindingitf = (BindingController)c.getFcInterface("binding-controller");
			String[] controllerInterfaces = controllerBindingitf.listFc();
			for(String controllerI : controllerInterfaces) {
				Interface controlInterface = (Interface) c.getFcInterface(controllerI);
				String controlInterfaceName = (controlInterface.getFcItfType().toString().split("/"))[0];
				String controlInterfaceUri = (controlInterface.getFcItfType().toString().split("/"))[1];
				
				if(ontocompo.fc.api.ServiceItf.class.isAssignableFrom(Class.forName(controlInterfaceUri))) {
					Object serviceO = controllerBindingitf.lookupFc(controllerI);
					Interface serviceInterface = (Interface) serviceO;
					String serviceInterfaceName = (serviceInterface.getFcItfType().toString().split("/"))[0];
					//String serviceInterfaceUri = (serviceInterface.getFcItfType().toString().split("/"))[1];
					Component serviceComponent = serviceInterface.getFcItfOwner();
					
					ontocompo.api.IntrospectionItf serviceIi = ontocompo.api.IntrospectionItf.class.cast(serviceComponent.getFcInterface("ontocompoIntrospectionItf"));
					String serviceUid = serviceIi.getUid();
					
					NameController serviceNameItf = (NameController) serviceComponent.getFcInterface("name-controller");
					String serviceName = serviceNameItf.getFcName();
					
					if(! this.components.containsKey(serviceName)) {
						this.components.put(serviceName, serviceUid);
						if(! this.bindings.containsKey(name + "." +  controlInterfaceName)) {
							this.bindings.put(name + "." +  controlInterfaceName, serviceName + "." + serviceInterfaceName);
						}
					}
				} else {
					Object elemO = controllerBindingitf.lookupFc(controllerI);
					Interface elemServerInterface = (Interface) elemO;
					String elemInterfaceName = (elemServerInterface.getFcItfType().toString().split("/"))[0];
					//String elemInterfaceUri = (elemServerInterface.getFcItfType().toString().split("/"))[1];
					Component elemServerComponent = elemServerInterface.getFcItfOwner();
					
					NameController serviceNameItf = (NameController) elemServerComponent.getFcInterface("name-controller");
					String serviceName = serviceNameItf.getFcName();
					
					if(this.components.containsKey(serviceName)) {
						if(! this.bindings.containsKey(name + "." +  controlInterfaceName)) {
							this.bindings.put(name + "." +  controlInterfaceName, serviceName + "." + elemInterfaceName);
						}
					} else {
						ontocompo.api.IntrospectionItf elemServerIi = ontocompo.api.IntrospectionItf.class.cast(elemServerComponent.getFcInterface("ontocompoIntrospectionItf"));
						String elemServerUid = elemServerIi.getUid();
						for(WebApplication wa : this.baseWebApp) {
							if(wa.getSelectedUIElements().containsKey(elemServerUid)) {
								if(! this.bindings.containsKey(name + "." +  controlInterfaceName)) {
									this.bindings.put(name + "." +  controlInterfaceName, serviceName + "." + elemInterfaceName);
								}
								break;
							}
						}
					}
				}
			}
		} catch (NoSuchInterfaceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public Component findComponent(String componentName) {
		for(WebApplication wa : this.baseWebApp) {
			for(String cUid : wa.getComponentsList().keySet()) {
				Component c = wa.getComponentsList().get(cUid);
				try {
					NameController nameItf = (NameController) c.getFcInterface("name-controller");
					String cName = nameItf.getFcName();
					
					if(componentName.equals(cName)) {
						return c;
					}
					
				} catch (NoSuchInterfaceException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return null;
	}
	
	public void writeGeneratedFile(String fileName, String content) {
		try {
			FileWriter fw = new FileWriter(Resources.GENERATEDFILES_DIRECTORY_PATH + "ontowebapp" + File.separator + fileName, true);
			
			BufferedWriter output = new BufferedWriter(fw);
			output.write(content);
			
			output.flush();
			
			output.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public String generateFractalFile() {
		String generated = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>" + "\n";
		generated += "<!DOCTYPE definition PUBLIC \"-//objectweb.org//DTD Fractal ADL 2.0//EN\" \"classpath://org/objectweb/fractal/adl/xml/basic.dtd\">" + "\n";
		generated += "" + "\n";
		generated += "<definition name=\"ontowebapp." + this.appName +  "App\">" + "\n";
		generated += "\t<interface name=\"htmlEntryPoint\" role=\"server\" signature=\"ontocompo.ui.api.html.HtmlScreenItf\"/>" + "\n";
		
		for(String componentName : this.components.keySet()) {
			generated += "\t<component name=\"" + componentName + "\" definition=\"" + this.components.get(componentName) + "\"/>" + "\n";
		}
		
		generated += "" + "\n";

		for(String client : this.bindings.keySet()) {
			generated += "\t<binding client=\"" + client + "\" server=\"" + this.bindings.get(client) + "\"/>" + "\n";
		}
		
		generated += "</definition>";
		
		return generated;
	}
	
	public String generateContainer(String containerClassName, String htmlId) {
		String requiredInterfaces = "";
		String methodContent = "";
		for(WebApplication wa : this.baseWebApp) {
			ArrayList<UIElementItf> selectedElementsWithoutContainer = wa.getSelectedUIElementsIdsAndHtml();
			for(UIElementItf uiei : selectedElementsWithoutContainer) {
				try {
					Component elemCompo = wa.getElementComponent(uiei.getId());
					
					NameController elemNameItf = (NameController) elemCompo.getFcInterface("name-controller");
					String elemName = elemNameItf.getFcName();

					BindingController bindingitf = (BindingController) elemCompo.getFcInterface("binding-controller");
					String[] interfaces = bindingitf.listFc();
					ArrayList<String> interfacesList = new ArrayList<String>();
					for(String i : interfaces) {
						interfacesList.add(i);
					}
					
					Object[] interfacesObjects = elemCompo.getFcInterfaces();
					
					for(Object o : interfacesObjects) {
						Interface i = (Interface) o;
						String interfaceName = (i.getFcItfType().toString().split("/"))[0];
						String interfaceUri = (i.getFcItfType().toString().split("/"))[1];
						
						
						if(! (
								interfaceName.equals("htmlEntryPoint") || interfaceName.equals("ontocompoIntrospectionItf") ||
								interfaceName.equals("name-controller") || interfaceName.equals("binding-controller") ||
								interfaceName.equals("lifecycle-controller") || interfaceName.equals("super-controller") || 
								interfaceName.equals("component") ||
								interfacesList.contains(interfaceName)
							)) {

								requiredInterfaces += "\t@Requires(name = \"" + elemName + "_" + interfaceName + "\")" + "\n";
								requiredInterfaces += "\tprivate " + interfaceUri + " " + elemName + "_" + interfaceName + ";" + "\n\n";
								
								methodContent += "\t\tthis." + elemName + "_" + interfaceName + ".init();" + "\n";
								methodContent += "\t\tthis.addUIElement(this." + elemName + "_" + interfaceName + ".getUIElementItSelf());" + "\n\n";
								
								this.bindings.put(containerClassName + "Component." + elemName + "_" + interfaceName, elemName + "." + interfaceName);
						}
					}
					
				} catch (RemoteException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (NoSuchInterfaceException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		
		String generated = "package ontowebapp;" + "\n";
		generated += "" + "\n";
		generated += "import org.objectweb.fractal.fraclet.annotations.Component;" + "\n";
		generated += "import org.objectweb.fractal.fraclet.annotations.Interface;" + "\n";
		generated += "import org.objectweb.fractal.fraclet.annotations.Requires;" + "\n";
		generated += "" + "\n";
		generated += "@Component(provides = {@Interface(name = \"htmlContainerItf\", signature = ontocompo.ui.api.html.HtmlContainerItf.class), @Interface(name = \"ontocompoIntrospectionItf\", signature = ontocompo.api.IntrospectionItf.class), @Interface(name = \"htmlEntryPoint\", signature = ontocompo.ui.api.html.HtmlElementItf.class)})" + "\n";
		generated += "public class " + containerClassName + " extends ontocompo.ui.lib.html.HtmlContainer implements ontocompo.ui.api.html.HtmlContainerItf {" + "\n";
		generated += "" + "\n";
		generated += requiredInterfaces;
		generated += "" + "\n";
		generated += "\tpublic " + containerClassName + "() {" + "\n";
		generated += "\t\tthis.uid = \"ontowebapp." + containerClassName + "\";" + "\n";
		generated += "\t\tthis.htmlId = \"" + htmlId + "\";" + "\n";
		generated += "\t}" + "\n";
		generated += "" + "\n";
		generated += "\t@Override" + "\n";
		generated += "\tpublic void init() {" + "\n";
		generated += methodContent;
		generated += "\t}" + "\n";
		generated += "" + "\n";
		generated += "}" + "\n";
		
		return generated;
	}
	
	public String generateScreen(String screenClassName, String htmlId) {
		String generated = "package ontowebapp;" + "\n";
		generated += "" + "\n";
		generated += "import ontocompo.ui.api.html.HtmlScreenItf;" + "\n";
		generated += "import ontocompo.ui.lib.html.HtmlContainer;" + "\n";
		generated += "" + "\n";
		generated += "import org.objectweb.fractal.fraclet.annotations.*;" + "\n";
		generated += "" + "\n";
		generated += "@Component(provides = {@Interface(name = \"htmlScreenItf\", signature = ontocompo.ui.api.html.HtmlScreenItf.class), @Interface(name = \"ontocompoIntrospectionItf\", signature = ontocompo.api.IntrospectionItf.class), @Interface(name = \"htmlEntryPoint\", signature = ontocompo.ui.api.html.HtmlElementItf.class)})" + "\n";
		generated += "public class " + screenClassName + " extends ontocompo.ui.lib.html.HtmlScreen implements HtmlScreenItf {" + "\n";
		generated += "" + "\n";
		generated += "@Requires(name = \"indexScreenContainer_html\")" + "\n";
		generated += "private ontocompo.ui.api.html.HtmlContainerItf indexScreenContainer_html;" + "\n";
		generated += "" + "\n";
		generated += "\tpublic " + screenClassName + "() {" + "\n";
		generated += "\t\tthis.uid = \"ontowebapp." + screenClassName + "\";" + "\n";
		generated += "\t\tthis.htmlId = \"" + htmlId + "\";" + "\n";
		generated += "\t}" + "\n";
		generated += "" + "\n";
		generated += "\t@Override" + "\n";
		generated += "\tpublic void init() {" + "\n";
		generated += "\t\tthis.indexScreenContainer_html.init();" + "\n";
		generated += "\t\tthis.setContainer((HtmlContainer) this.indexScreenContainer_html.getUIElementItSelf());" + "\n";
		generated += "\t}" + "\n";
		generated += "}" + "\n";
		
		return generated;
	}
}
